package com.etc.controller;

import com.etc.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.UUID;

@Controller
@RequestMapping("UploadFile")
public class UploadFile1 {
    @Autowired
    UserService service;
    @RequestMapping("addUserImg")
    public String addUserImg(@RequestParam("userName") String userName,
                           @RequestParam("password") String password,
                           @RequestParam("userPhone") String userPhone,
                           @RequestParam("userState") Integer userState,
                           @RequestParam("userLevel") Integer userLevel,
                           @RequestParam("userImg") MultipartFile userImg,
                           @RequestParam("userPrice") BigDecimal userPrice){
        String userImgName=UUID.randomUUID()+userImg.getOriginalFilename();
        File imgfile = new File("E:\\video\\" + userImgName);

        try {
            userImg.transferTo(imgfile);

        } catch (IOException e) {
            e.printStackTrace();
        }

        return "backstage/video/video_all";

    }
    @RequestMapping("addUserImgs")
    public void addUserImgs(@RequestParam(value = "myfile") MultipartFile[] myfiles){
        if (myfiles!=null && myfiles.length>0){
            for (MultipartFile myfile:myfiles){
                UUID uuid = UUID.randomUUID();
                String filename=uuid+myfile.getOriginalFilename();
                File file = new File("E:\\video\\" + filename);
                try {
                    myfile.transferTo(file);
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }

    }

}
